package com.wang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wang.domain.SmallCategory;
import com.wang.mapper.SmallCategoryMapper;
import com.wang.service.SmallCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author WangZai
 * @since 2023-05-06
 */
@Service
public class SmallCategoryServiceImpl extends ServiceImpl<SmallCategoryMapper, SmallCategory> implements SmallCategoryService {
    @Override
    public boolean addSmallCategory(SmallCategory category) {
        return this.save(category);
    }

    @Override
    public boolean deleteSmallCategoryById(Integer categoryId) {
        return this.removeById(categoryId);
    }

    @Override
    public boolean deleteSmallCategoryByLargeCategoryId(Integer largeCategoryId) {
        QueryWrapper<SmallCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("large_category_id",largeCategoryId);
        return this.remove(queryWrapper);
    }

    @Override
    public SmallCategory getSmallCategoryById(Integer categoryId) {
        return this.getById(categoryId);
    }

    @Override
    public SmallCategory getSmallCategoryByName(String categoryName) {
        QueryWrapper<SmallCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("small_category_name",categoryName);
        return this.getOne(queryWrapper);
    }

    @Override
    public List<SmallCategory> getSmallCategoryListByLargeCategoryId(Integer largeCategoryId) {
        QueryWrapper<SmallCategory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("large_category_id",largeCategoryId);
        return this.list(queryWrapper);
    }
}
